<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
    <head>

        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
        <title>出库单打印</title>
        <link rel="shortcut icon" href="/web/static/src/img/favicon.ico" type="image/x-icon">
        <link rel="stylesheet" href="/web/static/src/css/full.css">
        <link rel="stylesheet" href="/web/static/lib/fontawesome/css/font-awesome.css">
        <link rel="stylesheet" href="/web/static/lib/bootstrap/css/bootstrap.css">
        <link rel="stylesheet" href="/web/static/src/css/base.css">
        <script language="javascript" src="/lodop/static/src/js/mathlibrary.js"></script>

        <style type="text/css" id="style">
            body{padding: 10px; font-size: 10pt; overflow: auto}

            @media print
            {
                .print-hide {display:none}
            }

            .td_inline {
                display:block;
                overflow:hidden;
                white-space:nowrap;
                text-overflow:ellipsis;
                width: 370pt;
            }

            .nowrap{
                white-space:nowrap;
            }
            /*.table td.noborder{*/
            /*border-top: 0px;*/
            /*}*/

            .table thead tr td{font-weight: bold; font-size: 11pt}

            h4{margin: 0px;  padding: 0px;font-size: 14pt}

            h5{
                font-size:11pt; font-family:'黑体'; font-weight: bold; margin: 0px;  padding: 0px;
            }

            div{font-size: 10pt}

            span.foot_sign{border-bottom: 1px solid #ddd}

            .table tbody tr td{border-top: 1px solid #ddd;}
            .table tbody tr:last-child td{border-top: 1px solid #fff; padding: 0px}
            .table tbody tr.memo td {padding:0px; border-top:0px}

            td{font-size:10pt}

            .font-middle{
                font-size: 12pt;
            }


            .page_head{
                padding-bottom: 20px;
            }

            .underline{text-decoration: underline;}
        </style>
    </head>

    <body>
    <% if ids|length == 0  %>
    参数错误
    <% elif ids|length == 1  %>

    <div class="controls controls-row print-hide">
        <script>
        function LICENSES() {
            LODOP.SET_LICENSES("","CD9A14E608164F55F35D564059E8F43B","C94CEE276DB2187AE6B65D56B3FC2848","15F0BE661E7532B77491843CB2ED09AD");
        };

        function print_preview(){
            if (!LODOP.VERSION) return;
            LODOP.PRINT_INIT("东方团购中心订单${fake_order.name}");
    		LODOP.SET_PRINT_PAGESIZE(1, 1910, 2795, "1910x2795"); //2799的时候打5到8页会出现一行的向下偏移, 2795时目测还少走一点点1毫米左右吧, 2796时打15张后向下偏1行

            var printer_count = LODOP.GET_PRINTER_COUNT();
            var intPrinterIndex = -1;
            for (var i = 0; i < printer_count; i ++){
                if(LODOP.GET_PRINTER_NAME(i).indexOf('东方团购中心订单') >= 0){
                    intPrinterIndex = i;
                    break;
                }
            }
            if (intPrinterIndex == -1){
                alert('东方团购中心订单打印机不存在，无法打印');
                return;
            }
            LODOP.SET_PRINT_COPIES(2); //出货单默认为2张
            CreateOneFormPage1();
            if (LODOP.SET_PRINTER_INDEXA(intPrinterIndex+'')){
                LODOP.PRINT();
                document.getElementById('btn-print').innerHTML = "已经打印";
                document.getElementById('btn-print').className = "btn btn-primary disabled";
            }
        }
        window.onload = function(){
//            var xiaoxie = document.getElementById('spanGrandTotal').innerHTML;
//            var daxie = cmycurd(xiaoxie);
//            document.getElementById('spanGrandTotal').innerHTML = xiaoxie + " (" + daxie + ")";
            LICENSES();
            //如果存在父级，则自动打印
            if (parent.batch_print_next){
                document.getElementById('btn-print').innerHTML = "自动打印模式";
                document.getElementById('btn-print').className = "btn btn-primary disabled";
                setTimeout(function(){
                    print_preview();
                    setTimeout(function(){
                        parent.batch_print_next();
                    }, 1000)
                }, 2000)
            }
        }


    function CreateOneFormPage1(){
        var strStyle = "<style>td{font-size:13px}</style>";
        LODOP.ADD_PRINT_TABLE(165, 20, "96%", 500, strStyle + document.getElementById("div-body").innerHTML);
        //LODOP.SET_PRINT_STYLEA(0,"TableHeightScope", 1);
        //LODOP.SET_PRINT_STYLEA(0,"Vorient",3);
        //LODOP.SET_PRINT_STYLEA(0,"FontSize",8);

//        LODOP.ADD_PRINT_HTM(17, 120,"50%",200,document.getElementById("div-title").innerHTML);
//        LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
//        LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);

        LODOP.ADD_PRINT_HTM(75, 20,"96%",145,document.getElementById("div-header").innerHTML);
        LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
        LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);

        //送货人
        //LODOP.ADD_PRINT_HTM(720, 570, 200, 20, strStyle + document.getElementById("div-delivery-person").innerHTML);
        //LODOP.SET_PRINT_STYLEA(0,"ItemType",1);

        //反馈表
        strStyle = "<style>td{font-size:14px}</style>";
        LODOP.ADD_PRINT_HTM(740, 10, "96%", 300, strStyle + document.getElementById("div-feedback").innerHTML);
        LODOP.SET_PRINT_STYLEA(0,"ItemType",1);

        //签收人
        LODOP.ADD_PRINT_HTM(1000, 30, 600, 20, strStyle + document.getElementById("div-receiver-person").innerHTML);
        LODOP.SET_PRINT_STYLEA(0,"ItemType",1);

        //页码
        LODOP.ADD_PRINT_HTM(1025, 670, 150,30,"<span tdata='pageNO' style='font-size:12px'>第##页</span>/<span tdata='pageCount'  style='font-size:12px'>共##页</span>");
        LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
        //logo
//        LODOP.ADD_PRINT_IMAGE(0, 0, 100,60,"<img border='0' src='/dftg_lodop/static/src/img/800890_logo.jpg?3' width='100' height='60' />");
//        LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
        //条码
        LODOP.ADD_PRINT_BARCODE(8, 485, 260, 60, "Code93", "${fake_order.name}");
        LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
        //二维码
        LODOP.ADD_PRINT_BARCODE(900, 670, 100, 100,"QRCode","${url_prefix}/wx/stock/fake/${sale_order.id}");
        LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
//        LODOP.ADD_PRINT_TEXT(1084, 630, 150, 20,"扫码打印出库单");
//        LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
//        LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
    };


        function load_lodop(development){
            var script = document.createElement('script');
            var lodop_host = '192.168.0.10';
            if (development == 'development'){
                lodop_host = '127.0.0.1';
            }
            script.setAttribute('src', 'http://' + lodop_host + '/CLodopfuncs.js');
            // 把script标签加入head，此时调用开始
            document.getElementsByTagName('head')[0].appendChild(script);
            $("#btn-print").css("weui-form-preview-btn weui_btn weui_btn_default");
            $("#btn-print").text("打印");
            $("#btn-print").click(function(){
                print_picking();
            });
        }

        </script>

    <%  if options.priceHide  %>
        <a href="?options={&quot;priceHide&quot;:0}" class="btn btn-primary">显示价格</a>
    <%  else  %>
        <a href="?options={&quot;priceHide&quot;:1}" class="btn btn-primary">隐藏价格</a>
    <%  endif  %>
        <a id="btn-print" href="javascript:print_preview()" class="btn btn-primary">打印到订单打印机(自动2张)</a>
        （仓库搬了，如要给仓库，告诉真单编号叫仓库打印）
    </div>

<div id="div-header">
    <table border="0" cellSpacing="0" cellPadding="0" width="100%" style="font-size:12px">
        <tbody>
            <tr>
                <td colspan="3" style="font-family:黑体;font-size:14px;">
                    上海汉兆实业有限公司 <span style="font-family:黑体;font-size:16px;font-weight: bold"><% if fake_order.is_return %>
                        退货单
                    <% else %>
                        <% if fake_order.is_exchange %>
                            换货单
                        <% else %>
                            出库单
                        <% endif %>
                    <% endif %>
                    </span>
                </td>
            </tr>
            <tr>
                <td style="font-family:黑体;font-size:16px;font-weight: bold">
                    <% if fake_order.real_so_id %> （必须本人签收） <% endif %>

                </td>
                <td width="55%" style="font-family:楷体;font-size:14px;">
                    ${ fake_order.name }
                </td>
                <td style="font-family:楷体;font-size:14px;font-weight: bold; padding-right:15px" align="right">
                    <% if fake_order.is_return %>
                    计划退货:
                    <% else %>
                    计划发货:
                    <% endif %>
                    ${ fake_order.expected_delivery_time }
                </td>
            </tr>
            <tr>
                <td colspan="2" style="font-family:黑体;font-size:15px;font-weight: bold">

                    <!-- 企业名称 -->
                    <% if fake_order.partner_id.is_company %>
                        ${ fake_order.partner_id.name|default('', True) }
                    <% else %>
                        ${ fake_order.partner_id.name|default('', True) }${ fake_order.partner_id.parent_id.name|default('', True) }
                    <% endif %>
                    , 联系人:${sale_order.consignee}
                </td>
                <td style="padding-right:15px" align="right">
                    <% if fake_order.expected_delivery_time %>
                        具体时间: ${ fake_order.expected_delivery_hour }
                    <% else %>
                        未指定
                    <% endif %>
                </td>
            </tr>
            <tr><td colspan="4" align="right" style="padding-right:15px">
                地址:
                    <% if fake_order.province_id and fake_order.province_id.name != '上海市' %>
                    ${fake_order.province_id.name}
                    <% endif %>
                    <% if fake_order.city_id %>
                    ${fake_order.city_id.city_name}
                    <% endif %>
                    <% if fake_order.county_id %>
                    ${fake_order.county_id.county_name}
                    <% endif %>
                    ${ fake_order.street|default('', True) }
            </td></tr>
        </tbody>
    </table>
</div>


<div id="div-body">
    <table width="100%" border="0" cellSpacing="0" cellPadding="0" bordercolor="#000000" style="border-collapse:collapse;font-size:12px">
        <thead style="font-weight: bold">
            <tr>
                <td style="border-bottom: 1px solid #000000" width="15">#</td>
                <td style="border-bottom: 1px solid #000000">产品</td>
                <td nowrap="nowrap" style="border-bottom: 1px solid #000000">规格</td>
                <td nowrap="nowrap" style="border-bottom: 1px solid #000000"></td>
                <td nowrap="nowrap" style="border-bottom: 1px solid #000000; padding-right:15px" align="right">总数量</td>
                <td nowrap="nowrap" style="border-bottom: 1px solid #000000; padding-right:15px" align="right">发货数量</td>
                <td nowrap="nowrap" style="border-bottom: 1px solid #000000; padding-right:15px" align="right">单价</td>
                <td nowrap="nowrap" style="border-bottom: 1px solid #000000; padding-right:15px" align="right">小计</td>
            </tr>
        </thead>
        <tbody>
            <% for line in fake_order.order_line %>
            <tr>
                <td style="border-bottom: 1px solid #000000">${loop.index}</td>
                <td style="border-bottom: 1px solid #000000">
                        <span>[${line.product_id.default_code}] ${line.product_id.name}</span>
                </td>

                <td style="border-bottom: 1px solid #000000"><span>${line.product_id.prod_spec|default("", True)}</span></td>
                <td style="border-bottom: 1px solid #000000"${line.sale_note|default(" ", True)}</td>
                <td style="border-bottom: 1px solid #000000; padding-right:15px" align="right">${ line.product_uom_qty|int }</td>
                <td style="border-bottom: 1px solid #000000; padding-right:15px" align="right">${ line.product_uom_qty|int }</td>
                <td style="border-bottom: 1px solid #000000; padding-right:15px" align="right">${ line.price_unit }</td>
                <td style="border-bottom: 1px solid #000000; padding-right:15px" align="right">${ line.price_unit*line.product_uom_qty|round(2) }</td>
            </tr>
				<% for order_card in fake_order.fake_order_id %>
						<% if order_card.product_id.id==line.product_id.id %>
						<tr>
							<td></td>
							<td style="text-align: left;" colspan="7">
							券号:${order_card.starting_number.code}<% if order_card.continue_number!=1 %>~${order_card.ending_number}(${order_card.continue_number}张)<% else %> (${order_card.continue_number}张)<% endif %>
							</td>
						</tr>
						<% endif %>
				<% endfor %>
            <% endfor %>

            <tr><td colspan="4">
                    <!--<% if official_invoice_map.get(False) %>开票:${official_invoice_map.get(False)}张<% endif %>-->
                    <!--<% if official_invoice_map.get(True) %>开票:${official_invoice_map.get(True)}张(W)<% endif %>-->
                附带发票: _____张
                </td>
                <td colspan="4" align="right" style="padding-right:15px">
                    合计：${fake_order.amount_total}
                </td>
            </tr>

        </tbody>
        <tfoot>
          <tr>
            <td width="100%" colspan="4" style="font-size:13px;font-weight: bold;padding-right:5px">
                ${fake_order.note|default(' ',True)|replace('\n', '<br/>')|safe}
            </td>
          </tr>
        </tfoot>
    </table>
</div>

<!--<div id="div-delivery-person">-->
    <!--<table border="0" cellSpacing="0" cellPadding="0" width="160">-->
        <!--<tr><td align="right" width="60">送货人:</td><td style="border-bottom: 1px solid #000000; padding-left:30px" width="100" id="td_delivery_name">&nbsp;</td></tr>-->
    <!--</table>-->
<!--</div>-->

<div id="div-feedback">
    <hr style="border: 0; height:1px; border-bottom: 1px dashed #000000" />
    <table border="0" cellSpacing="0" cellPadding="0" width="100%">
        <tr>
            <td style="font-family:黑体;font-size: 16px;font-weight: bold" colspan="4" align="center">
                <!--客户回执-->
            </td>
        </tr>
        <tr>
            <td colspan="4"><span style="font-family:楷体;font-size: 14px;font-weight: bold">${fake_order.partner_id.name}</span></td>
        </tr>
        <tr>
            <td colspan="4">订单: ${fake_order.name},
                付款方式: <% if fake_order.payment_method %><% endif %>☐现金 &nbsp;
                ☐支票 &nbsp;
                ☐转账 &nbsp;
                ☐POS机

            </td>
        </tr>
        <tr>
            <td colspan="4">出库单: ${fake_order.name}, 产品共${fake_order.order_line|count}种, 中转箱(袋)共: _____箱(袋), 产品数量共:______(件 个 套)</td>
        </tr>
        <tr><td colspan="4">&nbsp;</td></tr>
        <tr><td colspan="4" style="padding-left:0px">注：1、为保障您的权益，准确无误后再进行签收。</td></tr>
        <tr><td colspan="4" style="padding-left:50px">务必请您在收货时与配送人员当场核对商品的</td></tr>
        <tr><td colspan="4" style="padding-left:50px">包装、种类、数量、规格等是否与订单一致。</td></tr>
        <tr><td colspan="4" style="padding-left:29px"></td></tr>
        <tr><td colspan="4" style="padding-left:29px">2、凡经签收，若非商品质量问题，一律不退不换。</td></tr>
        <tr><td colspan="4" style="padding-left:0px"></td></tr>
        <tr><td colspan="4">&nbsp;</td></tr>
        <tr><td colspan="4" style="padding-left:0px"></td></tr>
    </table>
</div>

<div id="div-receiver-person">
    <table border="0" cellSpacing="0" cellPadding="0" width="100%">
        <tr>
            <td width="120">销售:<span style="border-bottom: 1px solid #000000; padding-right:20px">${sale_order.user_id.name}</span></td>
            <td width="40">物流:</td>
            <td style="border-bottom: 1px solid #000000" width="150">&nbsp;</td>
            <td align="right" width="80">货品签收:</td>
            <td style="border-bottom: 1px solid #000000" width="150">&nbsp;</td>
            <td align="right" width="80">发票签收:</td>
            <td style="border-bottom: 1px solid #000000" width="150">&nbsp;</td>

        </tr>
    </table>
</div>

<div style="float:right; margin-top:-20px">
    <img src="/wx/work/qr_or_bar_code?type=QR&width=100&value=stock/fake/${sale_order.id}" width="100" height="100" />
</div>


    <% elif ids|length > 1  %>
        <a id="btn-batch-print" href="javascript:batch_print_next()" class="btn btn-primary">开始批量打印假单出库单</a>
        注: 一共${ids|length}单，请把出库单纸装好<br />
        <iframe id="single_print_iframe"
                width="100%" height="400px" style="margin-top:10px;border: 1px solid;" scrollin="yes"></iframe>
    <script language="javascript">
        var ids = ${ids};
        var current_ids_index = 0;

//        function isIe(){
//            return window.ActiveXObject ? true : false;
//        }
//        function iframe_onload(){
//            //alert('iframe onload');
//            var single_print_iframe = document.getElementById('single_print_iframe');
//            window.current_ids_index ++;
//        }
//        window.onload = function(){
//            var single_print_iframe = document.getElementById('single_print_iframe');
//            if ( isIe() ) {
//                single_print_iframe.attachEvent( "onload", iframe_onload );
//            } else {
//                single_print_iframe.onload = iframe_onload;
//            }
//        }

        function batch_print_next(){
            document.getElementById('btn-batch-print').innerHTML = "正在打印第" + (window.current_ids_index + 1) + "单";
            document.getElementById('btn-batch-print').className = "btn btn-primary disabled";
            if (window.current_ids_index < ids.length){
                var single_print_iframe = document.getElementById('single_print_iframe');
                var url = window.location.href;
                right_pos = url.lastIndexOf('/');
                url = url.substring(0, right_pos + 1);
                var order_id = ids[current_ids_index];
                //alert(order_id);
                single_print_iframe.src = url + order_id;
                window.current_ids_index ++;
            }
            else{
                document.getElementById('btn-batch-print').innerHTML = "已经全部打印完毕";
                document.getElementById('btn-batch-print').className = "btn btn-primary disabled";
            }
        }
    </script>
    <% endif %>
    <script src="http://${lodop_host}/jsonp_lodop.js"></script>
    </body>
</html>
